<template>
  <div id="login">
    <el-dialog width="350px" :visible="true" :show-close="false" :modal="false">
      <div slot="title">
        <img src="/static/logo.png" alt>问卷系统登录
      </div>
      <el-form ref="form" label-width="80px" label-position="left">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="form.password" >
          </el-input>  
        </el-form-item>
         <el-form-item>
        <el-button type="primary" @click="getuser">登录</el-button>
        <router-link to="/registered">立即注册</router-link>
      </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>

export default {
  data(){
    return{
      visible:true,
      form:{
        username:'',
        password:''
      }
    }
  },
  created(){
    this.islogin()
  },
  methods:{
    islogin(){
      this.axios.get('/users/islogin').then((ret)=>{
        let {data,error}=ret.data
        if(data==1){
         this.$router.push('/home')
        }
      })
    },
    getuser(){
      this.axios.post('/users/login',{
       ...this.form,
        // username:this.form.username,
        // password:this.form.password
      }).then((ret)=>{
        let{data}=ret.data
        console.log(data)
        this.store.set('userInfo',data)
        this.$router.push({
          name:'home'
        })
      }).catch(()=>{
         this.$message.error('用户名或密码错误');
      })
    }
  }
};
</script>

<style  scoped >
#login {
  background-color: #fff;
}
.ps1>i{
  display: block;
  width: 50px;
  height: 50px;
  border:1px solid red;
  position: absolute;
  z-index: 100;
  top:0px;
}
</style>
